project(CalPDOP CUDA CXX)

if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
    set(CMAKE_CUDA_ARCHITECTURES 80)
else()
    set(CMAKE_CUDA_ARCHITECTURES native)
endif ()

# 设置编译标准
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CUDA_STANDARD 17)
set(CMAKE_CUDA_STANDARD_REQUIRED ON)

include_directories(${CMAKE_SOURCE_DIR}/3rdlibs/include)
link_directories(${CMAKE_SOURCE_DIR}/3rdlibs/lib)

if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
    message(STATUS "Configuring for Linux")
    find_package(GDAL REQUIRED)
    include_directories(${GDAL_INCLUDE_DIRS})
endif()


if (CMAKE_BUILD_TYPE STREQUAL "Debug")
    set(CMAKE_OUT_DIR ${CMAKE_SOURCE_DIR}/out/build/debug)
else ()
    set(CMAKE_OUT_DIR ${CMAKE_SOURCE_DIR}/out/build/release)
endif ()
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_OUT_DIR}/CalPDOP)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_OUT_DIR}/CalPDOP)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_OUT_DIR}/CalPDOP)

add_executable(CalPDOP
        main.cu
        CuCalPDOP.cu
        Common.cu
        Ephemeris.cpp
        SatTime.cpp
)

set_target_properties(CalPDOP PROPERTIES CUDA_SEPARABLE_COMPILATION ON)


set(DLL_DIR "${CMAKE_SOURCE_DIR}/3rdlibs/bin")

if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
    target_include_directories(CalPDOP PRIVATE ${GDAL_INCLUDE_DIRS})
    target_link_libraries(CalPDOP PRIVATE
            ${GDAL_LIBRARIES}
            LibGridTIFF
            CuLibDGGSKernel
            LibDGGSKernel
            stdc++
            stdc++fs
            m
    )
    file(GLOB_RECURSE DLL_FILES "${DLL_DIR}/*.a")
    foreach(DLL_FILE ${DLL_FILES})
        file(COPY ${DLL_FILE} DESTINATION "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}")
    endforeach()

elseif (CMAKE_SYSTEM_NAME STREQUAL "Windows")
    target_link_libraries(CalPDOP
            LibGridTIFF
            CuLibDGGSKernel
            LibDGGSKernel
            gdal_i
    )
    file(GLOB_RECURSE DLL_FILES "${DLL_DIR}/*.dll")
    foreach(DLL_FILE ${DLL_FILES})
        file(COPY ${DLL_FILE} DESTINATION "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}")
    endforeach()
endif()
